package com.atguigu04.set;

public class User implements Comparable{
    String name;
    int age;

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        int value=0;
        if(this==o){
            return 0;
        }
        if(o instanceof User){
            User user=(User)o;
          value= this.age-user.age;
            if(value!=0){
                return value;
            }else{
                return this.name.compareTo(user.name);
            }
        }
        throw  new RuntimeException("");
    }
}
